﻿<!DOCTYPE html>
<html lang="zh-CN">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>新增销售订单</title>
    <script src="~/lib/vue/vue.global.min.js"></script>
    <script src="~/lib/element-plus/index.full.js"></script>
    <link href="~/lib/element-plus/index.min.css" rel="stylesheet" />
    <link href="~/lib/element-plus/index.css" rel="stylesheet" />
    <script src="https://cdn.jsdelivr.net/npm/axios/dist/axios.min.js"></script>

    <style>
       

        /* 主内容区域偏移，为固定菜单留出空间 */
        .container {
            width: 95%;
           margin: 20px auto 20px 5% ; /* 左边距设为5%，实现向右偏移 */
            border: none; /* 移除边框 */
            border-radius: 0; /* 移除圆角 */
            padding: 0; /* 移除内边距 */
            box-shadow: none; /* 移除阴影 */
            height: auto; /* 高度由内容撑开 */
        }

        .form-group {
            margin-bottom: 20px;
            border: 1px solid #ebeef5;
            border-radius: 4px;
            padding: 20px;
            box-shadow: 0 2px 12px 0 rgba(0, 0, 0, 0.1);


        }

        .form-item {
            margin-bottom: 5px;
        }

        .note-input {
            height: 100px;
        }

        .goods-table {
            margin-top: 16px;
        }

        .total-row {
            font-weight: bold;
        }

        .button-group {
            margin-top: 20px;
            display: flex;
            gap: 10px;
        }



       
    </style>
</head>

<body>
    <div class="container">
        <!-- 基础信息 -->
        <div class="form-group">
            <h4>基础信息</h4>
            <el-form ref="basicForm" :model="form" label-width="100px">
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="销售单号" required class="form-item">
                            <el-input v-model="form.sales_order_no" placeholder="自动获取系统编号" readonly></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="销售日期" required class="form-item">
                            <el-date-picker v-model="form.sales_date" type="date" placeholder="请选择" value-format="YYYY-MM-DD"></el-date-picker>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="8">
                        <el-form-item label="客户名称" required class="form-item">
                            <el-select v-model="form.customer_id"
                                       placeholder="请选择"
                                       v-on:change="handleCustomerChange">
                                <el-option v-for="item in customerOptions"
                                           :key="item.value"
                                           :label="item.label"
                                           :value="item.value">
                                </el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="4">
                        <el-form-item class="form-item" style="margin-left: -80px;">
                            <el-button type="text">设置</el-button>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="联系人" class="form-item">
                            <el-input v-model="form.contact_person" placeholder="请输入" disabled></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="联系方式" class="form-item">
                            <el-input v-model="form.contact_phone_number" placeholder="请输入" disabled></el-input>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12">
                        <el-form-item label="销售部门" class="form-item">
                            <div style="display: flex; align-items: center;">
                                <el-input v-model="form.salesDeptName"
                                          placeholder="请选择部门"
                                          readonly
                                          style="flex: 1; margin-right: 8px;">
                                </el-input>
                                <el-button type="primary"
                                           icon="el-icon-search"
                                           v-on:click="openOrgSelectDialog">
                                    选择
                                </el-button>
                            </div>
                            <el-input v-model="form.salesDeptId" type="hidden"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
                <el-row>
                    <el-col :span="12">
                        <el-form-item label="销售负责人" class="form-item">
                            <el-select v-model="form.person_in_charge" placeholder="请选择" v-on:change="handlePersonChange">
                                <el-option v-for="item in personInChargeOptions" :key="item.value" :label="item.label" :value="item.value"></el-option>
                            </el-select>
                        </el-form-item>
                    </el-col>
                    <el-col :span="12"></el-col>
                </el-row>
                <el-row>
                    <el-col :span="24">
                        <el-form-item label="备注" class="form-item">
                            <el-input v-model="form.note" type="textarea" placeholder="请输入备注" class="note-input"></el-input>
                        </el-form-item>
                    </el-col>
                </el-row>
            </el-form>
        </div>

        <!-- 树形选择弹窗 -->
        <el-dialog v-model="orgSelectDialogVisible"
                   title="选择销售部门"
                   width="450px"
                   style="z-index: 9999;">
            <div style="margin-bottom: 16px;">
                <el-input v-model="orgSearchKeyword"
                          placeholder="输入部门名称搜索"
                          clearable
                          v-on:keyup.enter="searchOrgTree">
                    <template #append>
                        <el-button type="primary"
                                   v-on:click="searchOrgTree"
                                   icon="Search"
                                   style="padding: 0 15px;">
                            搜索
                        </el-button>
                    </template>
                </el-input>
            </div>
            <el-tree :data="orgTree"
                     :props="{
                        value: 'organizationId',
                        label: 'organizationName',
                        children: 'children'
                    }"
                     v-on:node-click="handleOrgNodeClick"
                     node-key="organizationId"
                     :highlight-current="true"
                     default-expand-all>
            </el-tree>
            <template #footer>
                <div class="dialog-footer">
                    <el-button v-on:click="orgSelectDialogVisible = false">取消</el-button>
                    <el-button type="primary" v-on:click="confirmOrgSelect">确定</el-button>
                </div>
            </template>
        </el-dialog>

        <!-- 销售货品明细 -->
        <div class="form-group">
            <h4>销售货品明细</h4>
            <div style="margin-bottom: 16px;">
                <el-button type="success" v-on:click="addGoodsRow">添加</el-button>
                <el-button v-on:click="removeGoodsRow">移除</el-button>
            </div>
            <el-table :data="goodsList" border class="goods-table" v-on:cell-change="handleCellChange" style="width: 100%">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column label="序号" type="index" width="70"></el-table-column>
                <el-table-column prop="product_name" label="货品名称" width="100"></el-table-column>
                <el-table-column prop="product_code" label="货品编号" width="100"></el-table-column>
                <el-table-column prop="specification_model" label="规格型号" width="100"></el-table-column>
                <el-table-column prop="unit" label="单位" width="80"></el-table-column>
                <el-table-column prop="product_type_name" label="货品类型" width="100"></el-table-column>
                <el-table-column prop="current_inventory" label="当前库存" width="100"></el-table-column>
                <el-table-column prop="prod_num" label="货品数量" required width="200">
                    <template #default="scope">
                        <el-input-number v-model="scope.row.prod_num" :min="1" />
                    </template>
                </el-table-column>
                <el-table-column prop="selling_unit_price" label="销售单价" required width="120">
                    <template #default="scope">
                        <el-input v-model.number="scope.row.selling_unit_price" placeholder="请输入" />
                    </template>
                </el-table-column>
                <el-table-column prop="saleAmount" label="销售金额" width="150" align="right">
                    <template #default="scope">
                        {{ (scope.row.prod_num * scope.row.selling_unit_price).toFixed(2) }}
                    </template>
                </el-table-column>
                <el-table-column prop="note" label="备注" width="120">
                    <template #default="scope">
                        <el-input v-model="scope.row.note" placeholder="请输入" />
                    </template>
                </el-table-column>
                <el-table-column label="操作" width="80">
                    <template #default="scope">
                        <el-button type="text" style="color: #409EFF;" v-on:click="removeSingleRow(scope.$index)">移除</el-button>
                    </template>
                </el-table-column>
            </el-table>
            <el-row class="total-row" style="margin-top: 8px;">
                <el-col :span="20">合计</el-col>
                <el-col :span="2">货品数量：{{ totalQuantity }}</el-col>
                <el-col :span="2">销售金额：{{ totalAmount.toFixed(2) }}</el-col>
            </el-row>
        </div>

        <!-- 货品选择模态框 -->
        <el-dialog v-model="goodsSelectDialogVisible"
                   title="添加货品"
                   width="800px"
                   style="z-index: 9999;">
            <div style="margin-bottom: 16px; display: flex; align-items: center;">
                <el-input v-model="goodsSearchKeyword"
                          placeholder="请输入货品编号/名称"
                          clearable
                          style="flex: 1; width: 150px; margin-right: 8px;"
                          v-on:keyup.enter="searchGoods"></el-input>
                <el-select v-model="goodsUnit" placeholder="请选择单位" clearable
                           style="width: 150px; margin-right: 8px;">
                    <el-option v-for="item in industryOptions" :key="item.dictValue"
                               :label="item.dictLabel" :value="item.dictValue"></el-option>
                </el-select>
                <el-button type="primary" v-on:click="searchGoods">查询</el-button>
                <el-button v-on:click="resetGoodsSearch">重置</el-button>
            </div>
            <el-table :data="goodsSelectList"
                      border
                      style="width: 100%; margin-bottom: 16px;"
                      v-on:selection-change="handleGoodsSelectionChange">
                <el-table-column type="selection" width="55"></el-table-column>
                <el-table-column label="序号" type="index" width="70"></el-table-column>
                <el-table-column prop="product_code" label="货品编号" width="120"></el-table-column>
                <el-table-column prop="product_name" label="货品名称" width="120"></el-table-column>
                <el-table-column prop="specification_model" label="规格型号" width="120"></el-table-column>
                <el-table-column prop="unit" label="单位" width="80"></el-table-column>
                <el-table-column prop="stkInrefp" label="入库单价" width="100" align="right"></el-table-column>
                <el-table-column prop="current_inventory" label="当前库存" width="100" align="right"></el-table-column>
            </el-table>
            <el-pagination v-on:size-change="handleGoodsSizeChange"
                           v-on:current-change="handleGoodsCurrentChange"
                           :current-page="goodsCurrentPage"
                           :page-sizes="[1, 2, 3, 4]"
                           :page-size="goodsPageSize"
                           layout="total, sizes, prev, pager, next, jumper"
                           :total="goodsTotal"></el-pagination>
            <template #footer>
                <div class="dialog-footer">
                    <el-button v-on:click="goodsSelectDialogVisible = false">取消</el-button>
                    <el-button type="primary" v-on:click="confirmGoodsSelect">确定</el-button>
                </div>
            </template>
        </el-dialog>

        <!-- 操作按钮（新增保存草稿和保存并新增） -->
        <div class="button-group">
            <el-button v-on:click="goBack">关闭</el-button>
            <el-button  v-on:click="saveAsDraft">保存草稿</el-button>
            <el-button v-on:click="saveAndAddNew">保存并新增</el-button>
            <el-button type="primary" v-on:click="save">保存</el-button>
        </div>
    </div>

    <script>
        const { createApp, ref, onMounted, watch } = Vue;
        const app = createApp({
            setup() {
                // 表单基础信息
                const form = ref({
                    sales_order_no: '',
                    sales_date: '',
                    customer_name: '',
                    customer_id: '',
                    contact_person: '',
                    contact_phone_number: '',
                    salesDept: '',
                    person_in_charge: '',
                    note: '',
                    salesDeptId: '',
                    salesDeptName: '',
                    person_in_charge_name: ''
                });

                // 客户下拉框选项
                const customerOptions = ref([]);
                // 销售负责人下拉框选项
                const personInChargeOptions = ref([]);
                // 部门树形选择相关
                const orgSelectDialogVisible = ref(false);
                const orgTree = ref([]);
                const selectedOrgId = ref(null);
                const orgSearchKeyword = ref('');

                // 货品明细相关
                const goodsList = ref([]);
                const totalQuantity = ref(0);
                const totalAmount = ref(0);

                // 货品选择模态框相关
                const goodsSelectDialogVisible = ref(false);
                const goodsSearchKeyword = ref('');
                const goodsUnit = ref('');
                const goodsSelectList = ref([]);
                const goodsCurrentPage = ref(1);
                const goodsPageSize = ref(1);
                const goodsTotal = ref(0);
                const selectedGoods = ref([]);
                const industryOptions = ref([]);

                // 监听货品变化计算合计
                watch(goodsList, (newList) => {
                    totalQuantity.value = newList.reduce((sum, item) => sum + (item.prod_num || 0), 0);
                    totalAmount.value = newList.reduce((sum, item) => sum + (item.prod_num * item.selling_unit_price || 0), 0);
                }, { deep: true });

                // 加载客户列表
                const loadCustomerOptions = async () => {
                    try {
                        const response = await axios.get('/SalesOrder/GetCustomerSelectList');
                        customerOptions.value = response.data;
                    } catch (error) {
                        console.error('加载客户列表失败：', error);
                        ElementPlus.ElMessage.error('加载客户列表失败');
                    }
                };

                // 客户选择变化
                const handleCustomerChange = async (customerId) => {
                    if (!customerId) {
                        form.value.contact_person = '';
                        form.value.contact_phone_number = '';
                        return;
                    }
                    try {
                        const response = await axios.get('/SalesOrder/GetCustomerDetail', {
                            params: { customerId }
                        });
                        form.value.contact_person = response.data.contactPerson;
                        form.value.contact_phone_number = response.data.contactPhoneNumber;
                    } catch (error) {
                        console.error('获取客户详情失败：', error);
                        ElementPlus.ElMessage.error('获取客户信息失败');
                    }
                };

                // 加载部门树
                const loadOrgTree = async () => {
                    try {
                        const response = await axios.get('/SalesOrder/GetOrganizationTree');
                        orgTree.value = response.data;
                    } catch (error) {
                        console.error('加载部门树失败：', error);
                        ElementPlus.ElMessage.error('加载部门树失败');
                    }
                };

                // 打开部门选择弹窗
                const openOrgSelectDialog = async () => {
                    await loadOrgTree();
                    orgSelectDialogVisible.value = true;
                };

                // 部门节点点击
                const handleOrgNodeClick = (node) => {
                    selectedOrgId.value = node.organizationId;
                };

                // 确认选择部门
                const confirmOrgSelect = async () => {
                    if (!selectedOrgId.value) {
                        ElementPlus.ElMessage.warning('请选择部门');
                        return;
                    }
                    const findNode = (tree, id) => {
                        for (const node of tree) {
                            if (node.organizationId === id) return node;
                            if (node.children && node.children.length > 0) {
                                const childNode = findNode(node.children, id);
                                if (childNode) return childNode;
                            }
                        }
                        return null;
                    };
                    const selectedNode = findNode(orgTree.value, selectedOrgId.value);
                    if (selectedNode) {
                        form.value.salesDeptId = selectedNode.organizationId;
                        form.value.salesDeptName = selectedNode.organizationName;
                        await handleDeptChange(selectedNode.organizationId);
                        orgSelectDialogVisible.value = false;
                    }
                };

                // 部门变化加载负责人
                const handleDeptChange = async (deptId) => {
                    try {
                        const res = await axios.get('/SalesOrder/GetUserByDeptId', { params: { deptId } });
                        personInChargeOptions.value = res.data.map(item => ({
                            value: item.userId,
                            label: item.userName
                        }));
                        form.value.person_in_charge = '';
                    } catch (err) {
                        ElementPlus.ElMessage.error('加载负责人失败');
                    }
                };

                // 负责人变化加载部门
                const handlePersonChange = async (userId) => {
                    if (!userId) {
                        form.value.salesDeptId = '';
                        form.value.salesDeptName = '';
                        return;
                    }
                    try {
                        const res = await axios.get('/SalesOrder/GetDeptByUserId', { params: { userId } });
                        if (res.data) {
                            form.value.salesDeptId = res.data.organizationId;
                            form.value.salesDeptName = res.data.organizationName;
                        } else {
                            ElementPlus.ElMessage.warning('该用户无所属部门');
                            form.value.person_in_charge = '';
                        }
                    } catch (err) {
                        ElementPlus.ElMessage.error('获取部门失败');
                    }
                };

                // 搜索部门树
                const searchOrgTree = async () => {
                    try {
                        if (!orgSearchKeyword.value) {
                            await loadOrgTree();
                        } else {
                            const response = await axios.get('/SalesOrder/GetOrganizationTree2', {
                                params: { keyword: orgSearchKeyword.value }
                            });
                            orgTree.value = response.data;
                        }
                    } catch (error) {
                        console.error('搜索部门树失败：', error);
                        ElementPlus.ElMessage.error('搜索部门树失败');
                    }
                };

                // 加载所有负责人
                const loadAllPersonInCharge = async () => {
                    try {
                        const res = await axios.get('/SalesOrder/GetAllPersonInCharge');
                        personInChargeOptions.value = res.data.map(item => ({
                            value: item.userId,
                            label: item.userName
                        }));
                    } catch (err) {
                        ElementPlus.ElMessage.error('加载负责人列表失败');
                    }
                };

                // 获取单位字典
                const getIndustryDict = async () => {
                    try {
                        const response = await axios.get('/api/Dict/datas/Unit');
                        industryOptions.value = response.data;
                    } catch (error) {
                        console.error('获取单位字典失败：', error);
                        ElementPlus.ElMessage.error('获取单位数据失败');
                    }
                };

                // 打开货品选择弹窗
                const openGoodsSelectDialog = () => {
                    goodsSelectDialogVisible.value = true;
                    fetchGoodsList();
                };

                // 获取单位中文名称
                const getUnitLabel = (unitValue) => {
                    if (!unitValue) return '';
                    const unit = industryOptions.value.find(item => item.dictValue === unitValue);
                    return unit ? unit.dictLabel : '';
                };

                // 查询货品列表
                const fetchGoodsList = async () => {
                    try {
                        const unitLabel = getUnitLabel(goodsUnit.value);
                        const response = await axios.get('/SalesOrder/GetCustomerPage2', {
                            params: {
                                product_code: goodsSearchKeyword.value,
                                product_name: goodsSearchKeyword.value,
                                unit: unitLabel,
                                currentPage: goodsCurrentPage.value,
                                pageSize: goodsPageSize.value
                            }
                        });
                        goodsSelectList.value = response.data.data;
                        goodsTotal.value = response.data.total;
                    } catch (error) {
                        console.error('加载货品列表失败：', error);
                        ElementPlus.ElMessage.error('加载货品列表失败');
                    }
                };

                // 搜索货品
                const searchGoods = () => {
                    goodsCurrentPage.value = 1;
                    fetchGoodsList();
                };

                // 重置货品搜索
                const resetGoodsSearch = () => {
                    goodsSearchKeyword.value = '';
                    goodsUnit.value = '';
                    goodsCurrentPage.value = 1;
                    fetchGoodsList();
                };

                // 分页处理
                const handleGoodsSizeChange = (val) => {
                    goodsPageSize.value = val;
                    fetchGoodsList();
                };
                const handleGoodsCurrentChange = (val) => {
                    goodsCurrentPage.value = val;
                    fetchGoodsList();
                };

                // 选择货品变化
                const handleGoodsSelectionChange = (val) => {
                    selectedGoods.value = val;
                };

                // 确认选择货品
                const confirmGoodsSelect = () => {
                
                           if (selectedGoods.value.length === 0) {
          ElementPlus.ElMessage.warning('请选择至少一个货品');
          return;
        }

        selectedGoods.value.forEach(selected => {
          // 按“货品编号 + 规格型号”判断是否重复（多维度校验）
          const existingItem = goodsList.value.find(
            item => item.product_code === selected.product_code
              && item.specification_model === selected.specification_model
          );

          if (existingItem) {
            // 存在重复，提示用户不能重复添加，需修改已有行数量
            ElementPlus.ElMessage.warning(`货品【${selected.product_name}】（编号：${selected.product_code}）已存在，请在明细中修改数量`);
          } else {
            // 不存在，新增行
            goodsList.value.push({
              product_name: selected.product_name,
              product_code: selected.product_code,
              specification_model: selected.specification_model,
              unit: selected.unit,
              product_type_name: selected.product_type_name,
              current_inventory: selected.current_inventory,
              prod_num: 1, // 初始数量
              selling_unit_price: 0,
              note: ''
            });
          }
        });

        goodsSelectDialogVisible.value = false;
                };

                // 添加货品行
                const addGoodsRow = () => {
                    openGoodsSelectDialog();
                };

                // 移除选中货品行
                const removeGoodsRow = () => {
                    const selectedRows = goodsList.value.filter(row => row._checked);
                    if (selectedRows.length === 0) {
                        ElementPlus.ElMessage.warning('请勾选需要移除的货品行');
                        return;
                    }
                    goodsList.value = goodsList.value.filter(row => !row._checked);
                };

                // 移除单行货品
                const removeSingleRow = (index) => {
                    goodsList.value.splice(index, 1);
                };

                // 单元格变化处理
                const handleCellChange = () => {};

                // 获取销售单号
                const getSalesOrderNumber = async () => {
                    try {
                        const res = await axios.post("/NumberingRule/GenerateBusinessNumber",
                            { rule_id: 8 },
                            { headers: { 'Content-Type': 'application/json' } }
                        );
                        if (res.data.success) {
                            form.value.sales_order_no = res.data.businessNumber;
                        } else {
                            ElementPlus.ElMessage.error(res.data.message || '生成销售单号失败');
                        }
                    } catch (err) {
                        console.error("获取销售单号失败：", err);
                        ElementPlus.ElMessage.error("获取销售单号失败");
                    }
                };

                // 通用保存逻辑
                const commonSave = async (documentStatus) => {
                    try {
                        // 前端验证
                        if (!form.value.sales_date) {
                            ElementPlus.ElMessage.warning('请选择销售日期');
                            return Promise.reject();
                        }
                        if (!form.value.customer_id) {
                            ElementPlus.ElMessage.warning('请选择客户名称');
                            return Promise.reject();
                        }
                        if (goodsList.value.length === 0) {
                            ElementPlus.ElMessage.warning('请添加至少一条货品明细');
                            return Promise.reject();
                        }

                        // 构造提交数据
                        const orderData = {
                            customer_id: form.value.customer_id,
                            rule_id: 8,
                            sales_order_no: form.value.sales_order_no,
                            sales_date: form.value.sales_date,
                            document_status: documentStatus, // 1-草稿，2-待审核
                            person_in_charge: form.value.person_in_charge,
                            organizations_id: form.value.salesDeptId,
                            note: form.value.note,
                            create_by: 4,
                            is_delete: '0',
                            //create_time: new Date()
                        };

                        const detailsList = goodsList.value.map(item => ({
                            product_code: item.product_code,
                            selling_unit_price: item.selling_unit_price,
                            prod_num: item.prod_num,
                            purreturn_num: 0,
                            outbound_num: 0,
                            note: item.note,
                            create_by: '当前登录用户ID',
                            create_time: new Date(),
                            saleamount: (item.prod_num * item.selling_unit_price).toFixed(2),
                            is_delete: '0'
                        }));

                        // 提交保存
                        const response = await axios.post('/SalesOrder/AddSalesOrder', {
                            Order: orderData,
                            Details: detailsList
                        });

                        if (response.data.success) {
                            ElementPlus.ElMessage.success(
                                documentStatus === '1' ? '草稿保存成功' : '保存成功'
                            );
                            return Promise.resolve();
                        } else {
                            ElementPlus.ElMessage.error(response.data.message || '保存失败');
                            return Promise.reject();
                        }
                    } catch (error) {
                        console.error('保存失败:', error);
                        ElementPlus.ElMessage.error('网络异常，请重试');
                        return Promise.reject();
                    }
                };

                // 保存（待审核状态）
                const save = async () => {
                    await commonSave('2').then(() => {
                        window.location.href = '/SalesOrder/Index';
                    });
                };

                // 保存草稿（状态1）
                const saveAsDraft = async () => {
                     await commonSave('1').then(() => {
                        window.location.href = '/SalesOrder/Index';
                    });
                };

                // 保存并新增
                const saveAndAddNew = async () => {
                    await commonSave('2').then(() => {
                        resetForm();
                        getSalesOrderNumber();
                    });
                };

                // 重置表单
                const resetForm = () => {
                    form.value = {
                        sales_order_no: '',
                        sales_date: '',
                        customer_id: '',
                        contact_person: '',
                        contact_phone_number: '',
                        salesDeptId: '',
                        salesDeptName: '',
                        person_in_charge: '',
                        note: ''
                    };
                    goodsList.value = [];
                };

                // 返回上一页
                const goBack = () => {
                   window.location.href = '/SalesOrder/Index';
                };

                // 页面初始化
                onMounted(() => {
                    getSalesOrderNumber();
                    loadCustomerOptions();
                    loadAllPersonInCharge();
                    getIndustryDict();
                });

                return {
                    form,
                    customerOptions,
                    personInChargeOptions,
                    orgSelectDialogVisible,
                    orgTree,
                    selectedOrgId,
                    orgSearchKeyword,
                    goodsList,
                    totalQuantity,
                    totalAmount,
                    goodsSelectDialogVisible,
                    goodsSearchKeyword,
                    goodsUnit,
                    goodsSelectList,
                    goodsCurrentPage,
                    goodsPageSize,
                    goodsTotal,
                    selectedGoods,
                    industryOptions,

                    handleCustomerChange,
                    openOrgSelectDialog,
                    handleOrgNodeClick,
                    confirmOrgSelect,
                    searchOrgTree,
                    handleDeptChange,
                    handlePersonChange,
                    addGoodsRow,
                    removeGoodsRow,
                    removeSingleRow,
                    handleCellChange,
                    openGoodsSelectDialog,
                    searchGoods,
                    resetGoodsSearch,
                    handleGoodsSizeChange,
                    handleGoodsCurrentChange,
                    handleGoodsSelectionChange,
                    confirmGoodsSelect,
                    getSalesOrderNumber,
                    save,
                    saveAsDraft,
                    saveAndAddNew,
                    goBack
                };
            }
        });
        app.use(ElementPlus);
        app.mount('.container');
    </script>
</body>

</html>